package com.yzl.meeting.business.dao.impl;

import com.yzl.meeting.business.dao.UserDao;
import com.yzl.meeting.business.entity.User;
import com.yzl.meeting.business.utils.MyDbUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;


/**
 * @Title: UserServiceImpl
 * @Author: 姚志立
 * @Description:
 * @Date: 2020/10/9 15:13
 * @Version: 1.0
 */
public class UserDaoImpl implements UserDao {
    private QueryRunner qr = MyDbUtils.getQr();

    public User findUserByUserName(String userName) throws SQLException {
        String sql = "SELECT * FROM t_user WHERE userName=?";
        Object[] params = {userName};
        User user = qr.query(sql, new BeanHandler<User>(User.class), params);
        return user;
    }

    /**
     * 更新用户数据
     *
     * @param user
     */
    public void update(User user) throws SQLException {
        String sql = "UPDATE t_user SET userName=?,telPhone=?,password=?," +
                "photo=?,userRealName=?,token=?,expireTime=?,createTime=?,gender=?,lastLoginTime=? WHERE uId=?";
        Object[] params = {user.getUserName(), user.getTelPhone(), user.getPassword(), user.getPhoto(),
                user.getUserRealName(), user.getToken(), user.getExpireTime(), user.getCreateTime(),user.getGender(), user.getLastLoginTime(),user.getUId()};
        qr.update(sql, params);

    }
}